<!--
 * @Author: your name
 * @Date: 2021-07-24 11:39:16
 * @LastEditTime: 2021-07-26 11:49:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \miniprogram-cms\html\Logistice\ProductUpdate.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../css/element.css">
    <script src="../../js/zyrpublic.js?v=1.10"></script>
    <script src="../../javascript/vue.js"></script>
    <script src="../../javascript/elementui.js"></script>
    <script src="../../javascript/jquery.js"></script>
</head>

<body>
    <div class="page-wrap">
        <!-- <input class="impFile" @change="ExpressNum" @click="clickImport" type="file" id="file" name="file"
            > -->
        <div class="form-warp">
            <div class="form-title">产品更新表</div>
            <el-form class="el-form" size="small" label-width="80px">
                <el-form-item label="商品编号">
                    <el-input placeholder="请输入商品编号" v-model="queryForm.number"></el-input>
                </el-form-item>
                <el-form-item label="产品名称">
                    <el-input placeholder="请输入产品名称" v-model="queryForm.name"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="clickSearch">查询</el-button>
                </el-form-item>
            </el-form>
            <div style="margin-bottom: 15px;">
                <!-- <el-button type="primary" size="mini" icon="el-icon-edit" @click="clickImport">导入表格</el-button> -->
                <el-upload class="upload-demo" ref="upload" accept=".xlsx" action="UploadUrl()" :auto-upload="false"
                    :on-change="fileChange" :show-file-list="false">
                    <el-button slot="trigger" size="small" type="primary" @click="uploadFile">
                        选取文件</el-button>
                    <div slot="tip" class="el-upload__tip">只能上传xlsx文件，且不超过10M</div>
                </el-upload>
                <el-button type="primary" size="mini" icon="el-icon-download" @click="clickDownloadImportTemp">下载导入模板
                </el-button>
            </div>
        </div>
        <el-table :data="tabledata.list" style="width: 100%">
            <el-table-column prop="id" label="列表id"></el-table-column>
            <el-table-column prop="number" label="编号"></el-table-column>
            <el-table-column prop="name" label="产品名称"></el-table-column>
            <!-- <el-table-column label="操作">
                <template>
                    <span style="color:rgb(230, 55, 55);">删除</span>
                </template>
            </el-table-column> -->
        </el-table>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryForm.pageNo" :page-size="queryForm.pageSize" layout="total, sizes, prev, pager, next"
            :total="tabledata.totalNum">
        </el-pagination>
    </div>
    
    <script>
        var app = new Vue({
            el: '.page-wrap',
            data: {
                queryForm: {
                    pageNo: 1,
                    pageSize: 10,
                    number: '',
                    name: ''
                },
                tabledata: { list: [], totalNum: 0 },
                fileList: []
            },
            created() {
                this.getList()
            },
            methods: {
                handleSizeChange(val) {
                    this.queryForm.pageSize = val;
                    this.getList();
                },
                handleCurrentChange(val) {
                    this.queryForm.pageNo = val;
                    this.getList();
                },
                clickSearch() {
                    this.getList()
                },
                getList() {
                    $.ajax({
                        url: httpurl + "/selectProduceList",
                        headers: {
                            "Access-Control-Allow-Origin": "*",
                            "Access-Control-Allow-Methods": "*",
                            "Access-Control-Allow-Headers": "Authorization",
                            "Authorization": GetTokenInfo()
                        },
                        contentType: 'application/json',
                        cache: false,
                        data: this.queryForm,
                        success: (res) => {
                            if (res.rtnCode == 200) {
                                this.tabledata.totalNum = res.data.total;
                                this.tabledata.list = res.data.list;
                            } else {
                                this.tabledata.list = []
                                this.queryForm.pageNo = 1
                                this.tabledata.totalNum = 0;
                            }
                        }
                    });
                },
                clickDownloadImportTemp() {
                    window.location.href = 'http://192.168.30.101:8732/writeExcel'
                },
                clickImport() {

                },
                ExpressNum() {
                    var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
                    var form = new FormData(); // FormData 对象
                    form.append("file", fileObj); // 文件对象
                    console.log(form);
                },
                // 导入文件
                UploadUrl() {
                    // 因为action参数是必填项，我们使用二次确认进行文件上传时，直接填上传文件的url会因为没有参数导致api报404，所以这里将action设置为一个返回为空的方法就行，避免抛错
                    return ""
                },
                fileChange(file, fileList) {
                    console.log(file.raw);
                    // this.fileList.push(file.raw);
                    // console.log(this.fileList);
                    let form = new FormData();
                    form.append('file', file.raw);
                    $.ajax({
                        url: httpurl + "/addProductNews",
                        type: "post",
                        data: form,
                        processData: false,
                        contentType: false,
                        success: (data)=>{

                            if (data.rtnCode == 200) {
                                this.$message({
                                    message: data.msg,
                                    type: 'success'
                                })
                                this.getList()

                            } else {
                                this.$message.error(data.msg)
                            }
                        },
                        error: function (err) {
                            top.layer.alert("网络连接失败,稍后重试", err);
                        }

                    })
                },
                uploadFile() {
                }
            }
        })
    </script>
    <style>
        .page-wrap {
            padding: 10px;
        }

        .el-form {
            margin-top: 10px;
            display: flex;
            flex-wrap: wrap;
        }

        .form-title {
            font-size: 15px;
            margin-left: 10px;
        }
    </style>
</body>

</html>